package com.ccys.cms.service.userManagement.impl;


import com.ccys.cms.service.userManagement.TblMemberNoteWebService;
import com.ccys.common.util.StringUtil;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.userManagement.TblMemberNoteDTO;
import com.ccys.db.entity.TblMemberNote;
import com.ccys.db.mapper.TblMemberNoteMapper;
import com.ccys.db.page.PageUtils;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.vo.userManagement.TblMemberNoteWebVO;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * tbl_member_note管理
 */
@Service
@Slf4j
public class TblMemberNoteWebServiceImpl extends BaseServiceImpl<TblMemberNote> implements TblMemberNoteWebService {

    @Autowired(required = false)
    private TblMemberNoteMapper tblMemberNoteMapper;

    @Override
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, TblMemberNoteDTO dto) {
        if(StringUtil.isEmpty(dto.getMemberId())) {
            return ResponseResult.error("MemberId is not null");
        }
        PageUtils.startPage(request);
        List<TblMemberNoteWebVO> list = this.tblMemberNoteMapper.listObjectsCms(dto);
        PageInfo pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }


    @Override
    public ResponseResult change(TblMemberNote entity) {
        if (StringUtils.isBlank(entity.getId())) {
            // 新增
            //this.saveEntity(entity);
        } else {
            // 编辑
            TblMemberNote e = new TblMemberNote();
            e.setId(entity.getId());
            e.setContent(entity.getContent());
            this.updateEntityById(e);
        }
        return ResponseResult.success();
    }

    @Override
    public ResponseResult delete(TblMemberNote dto) {
        TblMemberNote entity = new TblMemberNote();
        entity.setId(dto.getId());
        entity.setDelFlag(1);
        this.updateEntityById(entity);
        return ResponseResult.success();
    }


}